import React from 'react';
import {PageContainer} from "@ant-design/pro-layout";
import {Button, Form, Input, message, Modal} from "antd";
import {setNewCode} from "@/services/people";

const Reset = (props) => {
  const {resetModal,codeModalShow,code}=props
  /**
   * 提交重置
   * @param values
   * @returns {Promise<void>}
   */
  const resetNewCode=async (values)=>{
    let resetRes=await setNewCode(values);
    if(resetRes.code === undefined){
      message.success('重置成功')
      resetModal(false)
    }
  }
  return (
    <PageContainer>
      <Modal title="重置密码"
             visible={codeModalShow}
             onCancel={()=>{resetModal(false)}}
             footer={null}
      >
        <Form
          name="basic"
          initialValues={code}
          onFinish={values=>{resetNewCode(values)}}
        >
          <Form.Item
            label="新密码"
            name="password"
            rules={
              [
                {
                  required: true,
                  message: '密码必填'
                },
                {
                  min: 6,
                  message: '密码最少6位'
                }
              ]
            }
          >
            <Input.Password />
          </Form.Item>
          <Form.Item
            name="id"
            hidden={true}
          >
            <Input.Password/>
          </Form.Item>
          <Form.Item>
            <Button type="primary" htmlType="submit">
              提交
            </Button>
          </Form.Item>
        </Form>
      </Modal>
    </PageContainer>
  );
};

export default Reset;
